﻿using SuperSocket.SocketBase;
using SuperSocket.SocketBase.Protocol;
using System;
using System.Text;

namespace IOA.MES.TcpService.SortService
{
    public class SortSession : AppSession<SortSession, StringRequestInfo>
    {
        private string LoggerId = string.Empty;

        protected override void OnSessionStarted()
        {
            this.Charset = Encoding.ASCII;
            LoggerId = RemoteEndPoint.ToString();
            Logger.Warn($"{LoggerId} 设备连接成功");
        }

        protected override void HandleUnknownRequest(StringRequestInfo requestInfo)
        {
            Logger.Warn($"{LoggerId} 消息无法处理，消息内容：{requestInfo.Body}");
            Logger.Error($"{LoggerId} 消息无法处理，消息内容：{requestInfo.Body}");
        }

        protected override void HandleException(Exception ex)
        {
            Logger.Warn($"{LoggerId} 消息处理异常：{ex.Message}", ex);
            Logger.Error($"{LoggerId} 消息处理异常：{ex.Message}", ex);
        }

        protected override void OnSessionClosed(CloseReason reason)
        {
            Logger.Warn($"{LoggerId} 连接已断开，断开原因：{reason.ToString()}");
            base.OnSessionClosed(reason);
        }
    }
}
